home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / SimHector / devices / RAM.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  2.1 KB  |  79 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // $Id: RAM.cxx,v 1.2 1994/08/22 07:35:24 bmott Exp $
  3. ///////////////////////////////////////////////////////////////////////////////
  4. // RAM.cxx 
  5. //
  6. // The Random Access Memory Device
  7. //
  8. // Sim68000 "Motorola 68000 Simulator"
  9. // Copyright (c) 1993
  10. // By: Bradford W. Mott
  11. // July 26,1993
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // $Log: RAM.cxx,v $
  15. // Revision 1.2  1994/08/22  07:35:24  bmott
  16. // Changed the device argument parsing
  17. //
  18. // Revision 1.1  1994/02/18  20:12:32  bmott
  19. // Initial revision
  20. //
  21. ///////////////////////////////////////////////////////////////////////////////
  22.  
  23. #include "String.h"
  24. #include "Regex.h"
  25.  
  26. #include "Tools.hxx"
  27. #include "BasicCPU.hxx"
  28. #include "RAM.hxx"
  29.  
  30. ///////////////////////////////////////////////////////////////////////////////
  31. // The class constructor
  32. ///////////////////////////////////////////////////////////////////////////////
  33. RAM::RAM(String args, BasicCPU* c)
  34.   : BasicDevice("RAM",args,c)
  35. {
  36.   Regex format("^BaseAddress=[0-9a-fA-F]+ Size=[0-9a-fA-F]+$");
  37.  
  38.   if(args.contains(format))
  39.   {
  40.     String remaining,base_arg,size_arg;
  41.  
  42.     remaining=args.after("BaseAddress=");
  43.     base_arg=remaining.before(" Size=");
  44.     size_arg=args.after(" Size=");
  45.  
  46.     base_address=StringToInt(base_arg)*c->Granularity();
  47.     size=StringToInt(size_arg)*c->Granularity();
  48.  
  49.     if ( size > 0 )
  50.       buffer=new unsigned char[size];
  51.     else
  52.       buffer=0;
  53.   }
  54.   else
  55.   {
  56.     SetErrorMessage("Invalid initialization arguments!");
  57.   }
  58. }
  59.  
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // The class destructor
  62. ///////////////////////////////////////////////////////////////////////////////
  63. RAM::~RAM()
  64. {
  65.   delete[] buffer;
  66. }
  67.  
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // Checks to see if the address maps into this device
  70. ///////////////////////////////////////////////////////////////////////////////
  71. char RAM::CheckMapped(unsigned long addr)
  72. {
  73.   if ( (addr>=base_address) && (addr<base_address+size) )
  74.     return(1);
  75.   else
  76.     return(0);
  77. }
  78.  
  79.